package GUI;

import swimming.VIPcard;
import use.VIPuse;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class totalVIP {
    private JPanel panel1;
    private JButton 查询所有会员记录Button;
    private JButton 会员卡充值Button;
    private JButton 新会员注册Button;
    private JButton 查询修改会员信息Button;
    private JButton 更改系统密码Button;
    private JButton 查询消费记录Button;
    private JButton 会员卡汇总记录Button;
    private JButton 使用会员卡Button;
    private javax.swing.JPanel JPanel;

    private JTable table2;
    private JTextField textField1;
    private JButton 确定Button1;
    private JButton 消费记录报表Button;

    private DefaultTableModel table;
    private Object[][] data;
    private String[] total={"电话","姓名","状态","类型","金额折扣","备注"};

    public static void iface()
    {
        JFrame frame = new JFrame("游泳馆会员管理系统");
        frame.setSize(500, 400);
        frame.setLocation(400, 200);

        totalVIP t1 = new totalVIP();
        frame.add(t1.panel1);

        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public totalVIP()   {
        会员卡充值Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new recharge().iface();
            }
        });
        查询消费记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new consume().iface();
            }
        });
        查询修改会员信息Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new revise().iface();
            }
        });
        更改系统密码Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new password().iface();
            }
        });
        新会员注册Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new VIP().iface();
            }
        });
        会员卡汇总记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new totalVIP().iface();
            }
        });
        使用会员卡Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new usecard().iface();
            }
        });

        查询所有会员记录Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                VIPuse vip=new VIPuse();
                table.setRowCount(0);
                try {
                    List<VIPcard> list=vip.搜索all();
                    for(VIPcard v:list)
                    {
                        String[] values={String.valueOf(v.getCardnum()),v.getName(),v.getState(),v.getCardtype(),v.getMoney(),v.getWhy(), "",""};
                        table.addRow(values);
                    }
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }

            }
        });
        确定Button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                VIPuse vip = new VIPuse();
                table.setRowCount(0);
                    try {
                        List<VIPcard> list1 = vip.搜索(textField1.getText());
                        for (VIPcard v : list1) {
                            String[] values = {v.getCardnum(), v.getName(), v.getState(), v.getCardtype(), v.getMoney(), v.getWhy()};
                            table.addRow(values);
                        }
                    } catch (SQLException ex) {
                        ex.printStackTrace();
                    }
            }
        });

        消费记录报表Button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new baobiao().iface();
            }
        });
    }

    public static void main(String[] args) {
        iface();
    }


    private void createUIComponents() {
        // TODO: place custom component creation code here
        data=null;
        table=new DefaultTableModel(data,total);
        table2=new JTable(table);
    }
}
